package com.laowang.project.system.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.laowang.framework.aspectj.lang.annotation.Log;
import com.laowang.framework.aspectj.lang.enums.BusinessType;

import org.springframework.web.bind.annotation.*;
import com.laowang.project.system.domain.MyFormInsurance;
import com.laowang.project.system.service.MyFormInsuranceService;
import com.laowang.framework.web.controller.BaseController;
import com.laowang.framework.web.domain.AjaxResult;
import com.laowang.common.utils.poi.ExcelUtil;
import com.laowang.framework.web.page.TableDataInfo;

/**
 * 保险Controller
 * 
 * @author laowang
 * @date 2024-04-24
 */
@Api(tags = "保险接口")
@RestController
@RequestMapping("/insurance")
public class MyFormInsuranceController extends BaseController {
    @Autowired
    private MyFormInsuranceService myFormInsuranceService;

    /**
     * 新增保险
     */
    @ApiOperation(value = "小程序端 新增保险表单",notes = "")
    @PostMapping("/web/add")
    public AjaxResult webadd(@RequestBody MyFormInsurance myFormInsurance) {
        return toAjax(myFormInsuranceService.insertMyFormInsurance(myFormInsurance));
    }


    /**
     * 查询保险列表
     */
    @ApiOperation(value = "查询保险列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:insurance:list')")
    @GetMapping("/list")
        public TableDataInfo list(MyFormInsurance myFormInsurance) {
        startPage();
        List<MyFormInsurance> list = myFormInsuranceService.selectMyFormInsuranceList(myFormInsurance);
        return getDataTable(list);
    }
    
    /**
     * 导出保险列表
     */
    @ApiOperation(value = "导出保险列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:insurance:export')")
    @Log(title = "保险", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MyFormInsurance myFormInsurance) {
        List<MyFormInsurance> list = myFormInsuranceService.selectMyFormInsuranceList(myFormInsurance);
        ExcelUtil<MyFormInsurance> util = new ExcelUtil<MyFormInsurance>(MyFormInsurance.class);
        return util.exportExcel(list, "insurance");
    }

    /**
     * 获取保险详细信息
     */
    @ApiOperation(value = "获取保险详细信息",notes = "")
    @PreAuthorize("@ss.hasPermi('my:insurance:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(myFormInsuranceService.selectMyFormInsuranceById(id));
    }

    /**
     * 新增保险
     */
    @ApiOperation(value = "新增保险",notes = "")
    @PreAuthorize("@ss.hasPermi('my:insurance:add')")
    @Log(title = "保险", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyFormInsurance myFormInsurance) {
        return toAjax(myFormInsuranceService.insertMyFormInsurance(myFormInsurance));
    }

    /**
     * 修改保险
     */
    @ApiOperation(value = "修改保险",notes = "")
    @PreAuthorize("@ss.hasPermi('my:insurance:edit')")
    @Log(title = "保险", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyFormInsurance myFormInsurance) {
        return toAjax(myFormInsuranceService.updateMyFormInsurance(myFormInsurance));
    }

    /**
     * 删除保险
     */
    @ApiOperation(value = "删除保险",notes = "")
    @PreAuthorize("@ss.hasPermi('my:insurance:remove')")
    @Log(title = "保险", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(myFormInsuranceService.deleteMyFormInsuranceByIds(ids));
    }
}
